package com.jy.modules.cims.component.funds.rest;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.data.common.dao.TCMmFundsrepayStreamDao;
import com.jy.modules.cims.data.common.dto.TCMmFundsrepayStreamDTO;
import com.jy.modules.cims.data.interact.funds.RequestRepayAccountDTO;
import com.jy.modules.cims.data.interact.funds.ResponseRepayAccountDTO;
import com.jy.platform.core.message.ResponseMsg;
/**
 * 划扣接口
 * @author zhangmi
 * @date
 */
@Controller
@RequestMapping(value = "/api/cims/fundsRepayAccountRest")
public class FundsRepayAccountRest {

	private static Logger logger = LoggerFactory.getLogger(FundsRepayAccountRest.class);
	@Autowired
	TCMmFundsrepayStreamDao tCMmFundsrepayStreamDao;
	
	/**
	 * 贷款-划扣登记
	 * @author lihong
	 * @date  2017年4月24日
	 * @param obj
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/loanDeductionRecord", method = RequestMethod.POST)
	public ResponseEntity<ResponseMsg<Void>> loanRepayOut(@RequestBody RequestRepayAccountDTO requestBody) throws Exception{
		logger.info("进入划扣登记接口：" + requestBody.getInterfaceNo() + "{}\r\n", JSON.toJSONString(requestBody));
		ResponseMsg<Void> responseMsg = new ResponseMsg<Void>();
		TCMmFundsrepayStreamDTO  tCMmFundsrepayStreamDTO=new TCMmFundsrepayStreamDTO();
		BeanUtils.copyProperties(requestBody,tCMmFundsrepayStreamDTO);
		//划扣状态 00--未划扣
		tCMmFundsrepayStreamDTO.setRepayStatus(CimsConstant.FUNDS_REPAY_STATUS_00);
		//是否处理 00--未处理
		tCMmFundsrepayStreamDTO.setIsDeal(CimsConstant.FUNDS_IS_DEAL_00);
		//是否有效 1--有效
		tCMmFundsrepayStreamDTO.setValidateState("1");
		Timestamp currTime = new Timestamp(System.currentTimeMillis());
		//创建日期
		tCMmFundsrepayStreamDTO.setCreateTime(currTime);
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", tCMmFundsrepayStreamDTO);
		tCMmFundsrepayStreamDao.insertTCMmFundsrepayStream(paramMap);
		ResponseEntity<ResponseMsg<Void>> responseEntity=new ResponseEntity<ResponseMsg<Void>>(responseMsg, HttpStatus.OK);
		System.out.println(responseEntity.getBody().toString());
		return responseEntity;
	}
	
	/**
	 * 单笔-贴息
	 * @author zhangmi
	 * @date  2017年4月24日
	 * @param obj
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/disCountOut", method = RequestMethod.POST)
	public ResponseEntity<ResponseMsg<ResponseRepayAccountDTO>> bankInfoCheck(@RequestBody RequestRepayAccountDTO requestBody) throws Exception{
		ResponseMsg<ResponseRepayAccountDTO> responseMsg = new ResponseMsg<ResponseRepayAccountDTO>();
		
		
		ResponseEntity<ResponseMsg<ResponseRepayAccountDTO>> responseEntity=new ResponseEntity<ResponseMsg<ResponseRepayAccountDTO>>(responseMsg, HttpStatus.OK);
		System.out.println(responseEntity.getBody().toString());
		return responseEntity;
	}
}
